package src.com.bank;

public class Account {
    private String id;
    private String name;
    private double balance;
    
    public Account(String id, String name, double balance) {
        this.id = id;
        this.name = name;
        if (balance < 0) {
            throw new IllegalArgumentException("初始余额不能为负数");
        }
        this.balance = balance;
    }
    
    public String getId() {
        return id;
    }
    
    public String getName() {
        return name;
    }
    
    public double getBalance() {
        return balance;
    }
    
    public void deposit(double amount) {
        if (amount <= 0) {
            throw new IllegalArgumentException("存款金额必须大于零");
        }
        balance += amount;
    }
    
    public void withdraw(double amount) throws InsufficientBalanceException {
        if (amount <= 0) {
            throw new IllegalArgumentException("取款金额必须大于零");
        }
        if (amount > balance) {
            throw new InsufficientBalanceException("余额不足，当前余额：" + balance);
        }
        balance -= amount;
    }
    
    public void transfer(Account target, double amount) throws InsufficientBalanceException {
        if (target == null) {
            throw new IllegalArgumentException("目标账户不能为空");
        }
        if (amount <= 0) {
            throw new IllegalArgumentException("转账金额必须大于零");
        }
        this.withdraw(amount);
        target.deposit(amount);
    }
    
    @Override
    public String toString() {
        return "Account{id='" + id + "', name='" + name + "', balance=" + balance + "}";
    }
}